﻿using SvGame.Objects;
using UtilLib;

namespace SvGame.Logic;

public static partial class GameLogic
{
    // 是否在战斗中
    public static bool IsFighting(this IRole me) => me.Comb.EnemyList.Count > 0;
    // 是对手
    public static bool FightHas(this IRole me, long uid) => me.Comb.EnemyList.Contains(uid);
    // 添加对手
    public static void FightOb(this IRole me, IRole ob)
    {
        me.Comb.EnemyList.TryAdd(ob.Uid);
    }
    // 移除对手
    public static void FightRemove(this IRole me, IRole ob)
    {
        me.Comb.EnemyList.Remove(ob.Uid);
    }
    // 移除所有对手
    public static void FightRemoveAll(this IRole me)
    {
        foreach (var item in me.Comb.EnemyList)
        {
            if (me.Room.GetRole(item, out var role))
            {
                role.FightRemove(me);
            }
        }
        me.Comb.EnemyList.Clear();
    }

    /// <summary>
    /// 清除不在同一房间的对手
    /// </summary>
    /// <param name="me"></param>
    /// <param name="ob"></param>
    public static void CheckFight(this IRole me)
    {
        if (me.Comb.EnemyList.Count <= 0)
        {
            return;
        }
        me.Comb.EnemyList.RemoveAll(it => !me.Room.HasRole(it));
    }
}
